package org.lgiavedoni.android.franq.command.system;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.lgiavedoni.android.franq.core.command.Command;
import org.lgiavedoni.android.franq.service.communication.CommunicationService;
import org.lgiavedoni.android.franq.service.cron.CronService;
import org.lgiavedoni.android.franq.util.collection.CollectionUtils;

public class CronCommand extends Command {

	private static final String OPTION_LIST = "list";

	@Override
	public String getCommandText() {
		return "cron";
	}

	@Override
	public void setOptions(Options options) {
		options.addOption(OPTION_LIST, false, "List all the cron jobs in the system");
	}

	@Override
	public boolean execute(CommandLine cmd) throws Exception {
		if (cmd.hasOption(OPTION_LIST)) {
			CommunicationService.inst.sendDefaultTextMessage(CollectionUtils.toString(CronService.inst.getCrons(), "\n"));
			return true;
		}
		return false;
	}
}